package org.study.module.jdk;

import org.study.entity.ClusterInfoEntity;
import org.study.shell.ShellBase;
import org.study.shell.ShellFile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * jdk安装shell命令
 */
public class JdkShell {
    public static List<String> install(String softPath, String installPath) {
        List<String> commands = new ArrayList<String>();
        commands.add("jdk_v=`java -version`");
        commands.add("if [[ $jdk_v == *\"jdk\"* ]]; then");
        commands.add("    echo \"JDK已安装！版本$jdk_v！\"");
        commands.add("    exit 1");
        commands.add("fi");
        installPath = installPath + "/jdk";
        commands.addAll(ShellFile.createPath(installPath));
        commands.add("sudo chmod -R 755 " + installPath);
        commands.addAll(ShellFile.findByName(softPath, "jdk", "jdk_tar"));
        commands.add("tar -xzvf $jdk_tar -C " + installPath);
        commands.add("cd " + installPath);
        commands.addAll(ShellFile.findByName(installPath, "jdk", "jdk_install"));
        commands.add("echo \"修改文件权限,755方便其他用户有权限执行\"");
        commands.add("sudo chmod -R 755 " + installPath);
        List<String> pros = new ArrayList<>();
        pros.add("export JAVA_HOME=$jdk_install");
        pros.add("export PATH=\\$PATH:\\$JAVA_HOME/bin");
        commands.addAll(ShellBase.addProfile(pros, "jdk_env.sh"));
        commands.add("java -version");
        return commands;
    }
}
